package com.teama4.shop.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.teama4.shop.domain.CommodityViewHistorys;
import com.teama4.shop.domain.ViewHistory;
import com.teama4.shop.domain.ViewHistoryExample;
import com.teama4.shop.domain.ViewHistoryPaging;
import com.teama4.shop.mapper.ViewHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ViewHistoryServiceImpl implements ViewHistoryService {
    @Autowired
    private ViewHistoryMapper viewHistoryMapper;
    @Override
    public long countByExample(ViewHistoryExample example) {
        return viewHistoryMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(ViewHistoryExample example) {
        return viewHistoryMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return viewHistoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(ViewHistory record) {
        return viewHistoryMapper.insert(record);
    }

    @Override
    public int insertSelective(ViewHistory record) {
        return viewHistoryMapper.insertSelective(record);
    }

    @Override
    public List<ViewHistory> selectByExample(ViewHistoryExample example) {
        return viewHistoryMapper.selectByExample(example);
    }

    @Override
    public ViewHistory selectByPrimaryKey(Integer id) {
        return viewHistoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(ViewHistory record, ViewHistoryExample example) {
        return viewHistoryMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(ViewHistory record, ViewHistoryExample example) {
        return viewHistoryMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(ViewHistory record) {
        return viewHistoryMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(ViewHistory record) {
        return viewHistoryMapper.updateByPrimaryKey(record);
    }


    @Override
    public List<CommodityViewHistorys> selectAllViewHistory() {
        return viewHistoryMapper.selectAllViewHistory();
    }

    @Override
    public ViewHistoryPaging selectViewHistoryByUserId(Integer userId,int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CommodityViewHistorys> commodityViewHistorys = viewHistoryMapper.selectViewHistoryByUserId(userId);
        Long total = ((Page)commodityViewHistorys).getTotal();
        return new ViewHistoryPaging(total,commodityViewHistorys);
    }
}
